package com.playcrab.adouban.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.SharedPreferences;
 
import com.google.gdata.client.douban.DoubanService;
import com.google.gdata.data.douban.Attribute;

public class DoubanAPI {

	private static DoubanAPI instance = null;
	private DoubanService service;

	private DoubanAPI() {
		service = new DoubanService(Constants.APP_NAME, Constants.API_KEY,
				Constants.SECRET);
	}

	public static synchronized DoubanAPI getInstance() {
		if (instance == null)
			instance = new DoubanAPI();
		return instance;
	}

	public DoubanService getService() {
		return service;
	}
	
	
	public Map<String, List<String>> buildAttributes(List<Attribute> attrs) {
		Map<String, List<String>> map = new HashMap<String, List<String>>();
		for(int i= 0; i< attrs.size(); i++){
			String name = attrs.get(i).getName();
			List<String> list = map.get(name);
			if( list == null){
			   list = new ArrayList<String>();
			   map.put(name, list);
			}
			list.add(attrs.get(i).getContent());
		} 
		return map;
	}
	
	public String joinList(List<String> list, String dot ){
		String str = "";
		for(int i = 0; i< list.size(); i++){
			str = str.concat(list.get(i));
			if(i!=list.size()-1){
				str = str.concat(dot);
			}
		}
		return str;
	}

}
